// i.r(t), i.d(t, { default: () => ShowcaseHotkeys })
import { KeyEvent } from "../event/KeyEvent"
import Module from "./Module"
import ViewmodeData from "../data/ViewmodeData"
import SettingsData from "../data/SettingsData"
import configConst from "../constant/config.const"
import SymbolList from "../SymbolList"
import { ChangeViewmodeCommand } from "../command/viewmode.command"
import modeEnum from "../enum/mode.enum"
import hotKeyEnum, { KeyState } from "../enum/hotKey.enum"
import viewmodeEnum from "../enum/viewmode.enum"
export default class ShowcaseHotkeys extends Module {
  inputCommandMap: any
  viewmodeData: ViewmodeData
  settings: any
  currentView: number
  meshViews: any
  issueCommand: any
  constructor() {
    super(...arguments),
      (this.name = "showcase-hotkeys"),
      (this.inputCommandMap = {
        [KeyState.PRESSED]: {
          [hotKeyEnum.ONE]: () => (
            this.viewmodeData.currentMode === viewmodeEnum.Panorama && (this.settings.setProperty(configConst.wireKey, !1), (this.currentView = 0)),
            this.switchToMode(modeEnum.INSIDE)
          ),
          [hotKeyEnum.TWO]: () => this.switchToMode(modeEnum.DOLLHOUSE),
          [hotKeyEnum.THREE]: () => this.switchToMode(modeEnum.FLOORPLAN),
          [hotKeyEnum.ZERO]: () => {
            const e = this.currentView++ % this.meshViews.length
            return this.meshViews[e]()
          }
        }
      }),
      (this.currentView = 0),
      (this.meshViews = [
        () => (this.settings.setProperty(configConst.wireKey, !1), this.switchToMode(modeEnum.MESH)),
        () => (this.settings.setProperty(configConst.wireKey, !0), this.switchToMode(modeEnum.MESH)),
        () => (this.settings.setProperty(configConst.wireKey, !0), this.switchToMode(modeEnum.INSIDE)),
        () => (this.settings.setProperty(configConst.wireKey, !1), this.switchToMode(modeEnum.INSIDE))
      ])
  }
  async init(e, t) {
    const i = await t.getModuleBySymbol(SymbolList.INPUT)
    ;([this.viewmodeData, this.settings] = await Promise.all([t.market.waitForData(ViewmodeData), t.market.waitForData(SettingsData)])),
      (this.issueCommand = t.commandBinder.issueCommand.bind(t.commandBinder)),
      i.registerHandler(KeyEvent, async e => {
        this.inputCommandMap[e.state] && this.inputCommandMap[e.state][e.key] && (await this.inputCommandMap[e.state][e.key]())
      })
  }
  async switchToMode(e) {
    this.viewmodeData.currentMode !== viewmodeEnum.Transition && (await this.issueCommand(new ChangeViewmodeCommand(e)))
  }
}
